//Copyright (c) 2024 Deng Zicheng
//        "CarController" is licensed under Mulan PSL v2.
//        You can use this software according to the terms and conditions of the Mulan PSL v2.
//        You may obtain a copy of Mulan PSL v2 at:
//        http://license.coscl.org.cn/MulanPSL2
//        THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
//        See the Mulan PSL v2 for more details.
package com.sinan.myapplication;

import ohos.ace.ability.AceAbility;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;
import ohos.agp.window.service.WindowManager;
import ohos.bluetooth.BluetoothHost;
import ohos.bundle.IBundleManager;


public class MainAbility extends AceAbility {

    private static final String PERMISSION_LOCATION = "ohos.permission.LOCATION";

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        //检查手机是否打开蓝牙
        bleBTServiceAbility.setContextMain(this);
        BluetoothHost bluetoothHost = BluetoothHost.getDefaultHost(this);
        if (bluetoothHost.getBtState() != BluetoothHost.STATE_ON) {
            bluetoothHost.enableBt();
        }
        //检查是否授权设备获取定位
        if (verifySelfPermission(PERMISSION_LOCATION) != IBundleManager.PERMISSION_GRANTED) {
            if (canRequestPermission(PERMISSION_LOCATION)) {
                requestPermissionsFromUser(new String[]{PERMISSION_LOCATION}, 0);
            } else {
                new ToastDialog(getContext()).setText("请进入系统设置进行授权").show();
            }
        }
    }

    @Override
    public void onStop() {
        super.onStop();
    }
}
